package com.jinrong.service.impl;/*

 */

import com.jinrong.entity.User;
import com.jinrong.mapper.UserMapper;
import com.jinrong.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @projectName: ShowYourLove
 * @package: com.jinrong.service
 * @className: UserService
 * @author: JackVictor
 * @description: TODO
 * @date: 2024/3/23 12:13
 * @version: 1.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void save(User user) {
        User user1=userMapper.getByAccount(user.getAccount());
        //检验邮箱是否已存在
        if (user1!=null) {
            throw new RuntimeException("用户名已存在");
        }
        userMapper.insert(user);
    }

    @Override
    public void login(User user) {
        //用户名是否存在
        User user1=userMapper.getByAccount(user.getAccount());
        //用户名和密码是否匹配
        user1 = userMapper.find(user);
        if(user1==null){
            throw new RuntimeException("用户名与密码不匹配");
        }
        //用户是否已经登录
        if(user1.getStatus()==1){
            throw new RuntimeException("用户已登录");
        }
        user.setStatus(1);
        userMapper.updateUser(user);
    }
}
